from django.db import models


# Create your models here.
class ActiveBaseModel(models.Model):
    active = models.SmallIntegerField(verbose_name="状态", choices=((1, "激活"), (0, "删除"),), default=1, null=True)

    class Meta:
        abstract = True


class Administrator(ActiveBaseModel):
    """ 管理员表 """
    username = models.CharField(verbose_name="用户名", max_length=32, db_index=True)
    password = models.CharField(verbose_name="密码", max_length=64)
    create_date = models.DateTimeField(verbose_name="创建日期", auto_now_add=True)


class Category(ActiveBaseModel):
    """分类表"""
    category_name = models.CharField(max_length=255, default=None)
    priority_num = models.IntegerField(verbose_name='优先级的总数', default=0)


class ContentManage(ActiveBaseModel):
    """内容管理"""
    content_id = models.AutoField(verbose_name="内容ID", primary_key=True)
    content_title = models.CharField(verbose_name='小标题', max_length=32, null=True, default=None)
    content_detail = models.TextField(verbose_name='详细内容', null=True, default=None)
    content_priority = models.IntegerField(verbose_name='优先级', null=True, default=1)
    content_category = models.ForeignKey(to='Category', on_delete=models.CASCADE)
    content_imgs = models.ManyToManyField(to='ImgModel', verbose_name='图片集', blank=True)


class ImgModel(ActiveBaseModel):
    content_img = models.FileField(verbose_name='图片', blank=True, max_length=512, null=True,
                                   default=None)


class Message(models.Model):
    """留言"""
    msg_id = models.AutoField(primary_key=True)
    msg_name = models.CharField(verbose_name='姓名', max_length=128, default=None, null=True)
    msg_phone = models.CharField(verbose_name='联系电话', max_length=128, default=None, null=True)
    msg_text = models.TextField(verbose_name='留言', default=None, null=True)
